<template>
  <ContentWrap>
    <div class="btn">
      <el-button
        type="primary"
        @click="handleForm('通过')"
        :loading="btnLoading"
        v-if="formType === 'update'"
        v-hasPermi="['technology:audit-task-ticket:pass']"
      >
        通过
      </el-button>
      <el-button
        type="danger"
        @click="handleForm('不通过')"
        :loading="btnLoading"
        v-if="formType === 'update'"
        v-hasPermi="['technology:audit-task-ticket:unpass']"
      >
        不通过
      </el-button>
      <el-button
        plain
        @click="goBack"
      >
        返回
      </el-button>
    </div>
    <detail ref="detailRef" :style="`overflow-y: auto; height: ${contentHeight}px`" :detailData="formData" />
  </ContentWrap>
</template>
<script setup lang="ts">
import * as AuditTaskTicketApi from '@/api/technology/auditTaskTicket'
import * as ComponentApi from '@/api/componentApi/index'
import { useTagsViewStore } from '@/store/modules/tagsView'
import detail from '../components/completionOrder/index.vue'
const message = useMessage() // 消息弹窗

const btnLoading = ref(false) //按钮加载中
const formType = ref('') // 表单的类型：view - 查看；update - 修改
const formData = ref({
  id: undefined,
  event: undefined,
  designCompletionNumber: undefined,  //设计完工单编号
  taskId: undefined, //任务单id
  taskNumber: undefined, //任务单号
  process: undefined, //任务完成进度
  productDrawingNumber: undefined, //产品图号
  productName: undefined, //产品名称
  productType: undefined, //产品类型
  productNumber: undefined, //产品编号
  partName: undefined, //部件名称
  dictDrawingType: undefined, //出图类型
  drawingContent: undefined, //出图内容
  changeContent: undefined, //改动内容
  alerts: [], //图纸改动数量
  remark: undefined, //备注
  dictTaskCompleteStatus: undefined, //任务状态
  proofreaderOpinion: undefined, //校对意见
  proofreader: undefined,
  proofreaderName: undefined, //校对人姓名
  verifiorTime: undefined, //校对时间
  proofreaderTime: undefined,
  approverName: undefined, //审核人
  approverOpinion: undefined, //审核意见
  auditorTime: undefined, //审核时间
  approver: undefined,
  approverTime: undefined,
  ratifyResult: undefined, //批准结果
  ratifiorName: undefined, //批准人
  ratifior: undefined,
  ratifyTime: undefined, //批准时间
  customerCode: undefined, //客户代码
  productStandard: undefined, //产品规格
  drawings: undefined, //图纸清单
  verifyParams: undefined, //校对参数
  baseParams: undefined //基本参数
})
const contentHeight = ref(0)

// 提交
const detailRef = ref()
const handleForm = async (event) => {
  if (!detailRef.value.formData.approverOpinion) {
    message.notifyError('没有填写校对意见')
    return
  }
  btnLoading.value = true
  message.success('操作成功')
  try {
    detailRef.value.formData.event = event
    const data = detailRef.value.formData as unknown as AuditTaskTicketApi.verifyTaskTicketVO
    await ComponentApi.handleTaskTicket(data)
    message.success('操作成功')
    goBack()
  } finally {
    btnLoading.value = false
  }
}

/**返回 */
const tagsViewStore = useTagsViewStore()
const route = useRouter() // 路由
const goBack = async () => {
  //获取当前路由并删除tagView
  tagsViewStore.delView(route.currentRoute.value)
  //跳转列表页
  route.push({
    path: '/technology/technology/drawingProduction/auditTaskTicket'
  })
}

// 获取数据
const { query } = useRoute() // 路由的查询
const getData = async () => {
  btnLoading.value = true
  formType.value = (query as any).type
  formData.value = await ComponentApi.getTaskTicket((query as any).id)
  btnLoading.value = false
}

// 初始化
onMounted(async () => {
  contentHeight.value = document.body.clientHeight - 132 - 57
  getData()
})

</script>
<style lang="scss" scoped>
.btn {
  margin-bottom: 10px;
}
</style>
